//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "Concentrating1dMesher.h"
using namespace Cephei::QL::Methods::Finitedifferences::Meshers;
#include <gen/QL/Methods/Finitedifferences/Meshers/Fdm1dMesher.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::CConcentrating1dMesher (Double start, Double end, UInt64 size) : CFdm1dMesher(CConcentrating1dMesher::typeid)
{
    try
    {
#ifdef HANDLE
        _phConcentrating1dMesher = NULL;
#endif
        QuantLib::Real _start = (QuantLib::Real)ValueHelper::Convert (start); //d
        QuantLib::Real _end = (QuantLib::Real)ValueHelper::Convert (end); //d
        QuantLib::Size _size = (QuantLib::Size)ValueHelper::Convert (size); //d
        _ppConcentrating1dMesher = new boost::shared_ptr<QuantLib::Concentrating1dMesher> (new QuantLib::Concentrating1dMesher ( _start,  _end,  _size ));
        SetFdm1dMesher (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppConcentrating1dMesher));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::CConcentrating1dMesher (boost::shared_ptr<QuantLib::Concentrating1dMesher>& childNative, Object^ owner) : CFdm1dMesher(CConcentrating1dMesher::typeid)
{
#ifdef HANDLE
	_phConcentrating1dMesher = NULL;
#endif
	_ppConcentrating1dMesher = &childNative;
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppConcentrating1dMesher));
}
Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::CConcentrating1dMesher (QuantLib::Concentrating1dMesher& childNative, Object^ owner) : CFdm1dMesher(CConcentrating1dMesher::typeid)
{
#ifdef HANDLE
	_phConcentrating1dMesher = NULL;
#endif
	_ppConcentrating1dMesher = new boost::shared_ptr<QuantLib::Concentrating1dMesher> (&childNative);
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppConcentrating1dMesher));
    _Concentrating1dMesherOwner = owner;
    _Fdm1dMesherOwner = owner;
}

Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::CConcentrating1dMesher (CConcentrating1dMesher^ copy) : CFdm1dMesher(CConcentrating1dMesher::typeid)
{
#ifdef HANDLE
	_phConcentrating1dMesher = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppConcentrating1dMesher = new boost::shared_ptr<QuantLib::Concentrating1dMesher> (copy->GetShared());
        _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppConcentrating1dMesher));
    }
}
Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::CConcentrating1dMesher (PLATFORM::Type^ t) : CFdm1dMesher(CConcentrating1dMesher::typeid)
{
#ifdef HANDLE
	_phConcentrating1dMesher = NULL;
#endif
	if (!t->IsSubclassOf(CConcentrating1dMesher::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::CConcentrating1dMesher (QuantLib::Handle<QuantLib::Concentrating1dMesher>& childNative, Object^ owner)  : CFdm1dMesher(CConcentrating1dMesher::typeid)
{
	_phConcentrating1dMesher = &childNative;
	_ppConcentrating1dMesher = &static_cast<boost::shared_ptr<QuantLib::Concentrating1dMesher>>(childNative.currentLink());
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppConcentrating1dMesher));
    _Concentrating1dMesherOwner = owner;
}
Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::CConcentrating1dMesher (QuantLib::Handle<QuantLib::Concentrating1dMesher> childNative)  : CFdm1dMesher(CConcentrating1dMesher::typeid)
{
	_phConcentrating1dMesher = &childNative;
	_ppConcentrating1dMesher = &static_cast<boost::shared_ptr<QuantLib::Concentrating1dMesher>>(childNative.currentLink());
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppConcentrating1dMesher));
}
#endif
#ifdef STRUCT
Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::CConcentrating1dMesher (QuantLib::Concentrating1dMesher childNative)  : CFdm1dMesher(CConcentrating1dMesher::typeid)
{
#ifdef HANDLE
	_phConcentrating1dMesher = NULL;
#endif
	_ppConcentrating1dMesher = new boost::shared_ptr<QuantLib::Concentrating1dMesher> (new QuantLib::Concentrating1dMesher (childNative));
    _ppFdm1dMesher = new boost::shared_ptr<QuantLib::Fdm1dMesher> (boost::dynamic_pointer_cast<QuantLib::Fdm1dMesher> (*_ppConcentrating1dMesher));
}
#endif

Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::~CConcentrating1dMesher ()
{
    if (_ppConcentrating1dMesher != NULL)
    {
	    delete _ppConcentrating1dMesher;
        _ppConcentrating1dMesher = NULL;
    }
}
Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::!CConcentrating1dMesher ()
{
    if (_ppConcentrating1dMesher != NULL)
    {
	    delete _ppConcentrating1dMesher;
    }
}
QuantLib::Concentrating1dMesher& Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::GetReference ()
{
    if (_ppConcentrating1dMesher == NULL) throw REFNEW NativeNullException ();
	return **_ppConcentrating1dMesher;
}
boost::shared_ptr<QuantLib::Concentrating1dMesher>& Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::GetShared ()
{
    if (_ppConcentrating1dMesher == NULL) throw REFNEW NativeNullException ();
	return *_ppConcentrating1dMesher;
}
QuantLib::Concentrating1dMesher* Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::GetPointer ()
{
    if (_ppConcentrating1dMesher == NULL) throw REFNEW NativeNullException ();
	return &**_ppConcentrating1dMesher;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Concentrating1dMesher>& Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::GetHandle ()
{
	if (_phConcentrating1dMesher == NULL)
	{
		_phConcentrating1dMesher = new Handle<QuantLib::Concentrating1dMesher> (*_ppConcentrating1dMesher);
	}
	return *_phConcentrating1dMesher;
}
#endif
bool Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher::HasNative () 
{
	return (_ppConcentrating1dMesher != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Methods::Finitedifferences::Meshers::IConcentrating1dMesher^ Cephei::QL::Methods::Finitedifferences::Meshers::CConcentrating1dMesher_Factory::Create (Double start, Double end, UInt64 size)
{
    return REFNEW CConcentrating1dMesher ( start,  end,  size);
}
